package cn.rongdao.jrkabao.ui.takephoto.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRImageLoad;

import java.util.List;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.takephoto.OtherImageDataBean;


/**
 * Created by jiangyongxing on 2016/7/21.
 * 描述：
 */
public class OtherImageDataAdapter extends RecyclerView.Adapter<OtherImageDataAdapter.OtherImageDataViewHolder> {

    private List<OtherImageDataBean> list;
    private OnItemActionListener mOnItemActionListener;

    public OtherImageDataAdapter(List<OtherImageDataBean> list) {
        this.list = list;
    }

    @Override
    public OtherImageDataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_other_image_data, parent, false);
        return new OtherImageDataViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final OtherImageDataViewHolder holder, final int position) {
        holder.itemName.setText(list.get(position).getOther_profile_cn());
        FRImageLoad.loadImage(list.get(position).getPicture(), holder.itemPic, R.drawable.addphoto);
        holder.itemPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemActionListener != null)
                    mOnItemActionListener.onClickPicSend(position, holder.itemPic, list.get(position).getConfig_id());
            }
        });
    }


    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public void setOnItemActionListener(OnItemActionListener onItemActionListener) {
        this.mOnItemActionListener = onItemActionListener;
    }

    /**********
     * 定义点击事件
     **********/
    public interface OnItemActionListener {
        void onClickPicSend(int pos, ImageView itemPic, int config_id);
    }

    class OtherImageDataViewHolder extends RecyclerView.ViewHolder {
        TextView itemName;
        ImageView itemIcon;
        ImageView itemPic;
        RelativeLayout itemRl;

        OtherImageDataViewHolder(View layout) {
            super(layout);
            itemName = (TextView) layout.findViewById(R.id.item_other_image_data_name);
            itemRl = (RelativeLayout) layout.findViewById(R.id.item_other_image_data_rl);
            itemIcon = (ImageView) layout.findViewById(R.id.item_other_image_data_icon);
            itemPic = (ImageView) layout.findViewById(R.id.item_other_image_data_pic);
        }
    }


}
